package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/4/1 15:37
 * @since v1.0
 */
@Getter
public enum CheckRepeatRuleEnum {
    NAME(1,"enum.checkRepeatRule.name.name"),
    PHONE(2,"enum.checkRepeatRule.name.phone")
    ;
    private Integer code;
    private String name;

    CheckRepeatRuleEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public static CheckRepeatRuleEnum getByCode(Integer rule) {
        for (CheckRepeatRuleEnum checkRepeatRuleEnum : values()){
            if (Objects.equals(rule,checkRepeatRuleEnum.getCode())){
                return checkRepeatRuleEnum;
            }
        }
        return null;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
